<template>
  <div>
    <el-dialog
      title="提示"
      :visible.sync="dialoghospitalization"
      width="30%"
      :before-close="handleClose"
    >
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="150px"
        class="demo-ruleForm"
      >
        <el-form-item label="最近第一次入院时间" prop="admissionDate">
          <el-date-picker
            v-model="ruleForm.admissionDate"
            type="datetime"
            placeholder="选择日期时间"
            default-time="12:00:00"
            style="width: 100%;"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="住院原因" prop="hospitalStays">
          <el-input v-model="ruleForm.hospitalStays" placeholder="住院原因"></el-input>
        </el-form-item>
        <el-form-item label="住院机构" prop="inpatientInstitution">
          <el-input v-model="ruleForm.inpatientInstitution" placeholder="住院机构"></el-input>
       
        </el-form-item>

        <el-form-item label="健康恢复情况" prop="recoveryCondition">
          <el-select
            v-model="ruleForm.recoveryCondition"
            placeholder="请选择健康恢复情况"
            style="width: 100%"
          >
            <el-option
              v-for="(item, index) in dict.type.health_recovery"
              :key="index"
              :label="item.label"
              :value="item.value"
              :disabled="item.disabled"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="handleSubmit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { addhospitalization, updatehospitalization } from "@/api/cluster/condition";
export default {
  props: ["dialoghospitalization", "oldManId", "ruleForm"],
  dicts: [
    "health_recovery",
  ],
  data() {
    return {
      dialogVisible: false,
      rules: {
        admissionDate: [
          {
            required: true,
            message: "请输入最近第一次入院时间",
            trigger: "blue",
          },
        ],
        hospitalStays: [
          {
            required: true,
            message: "请输入住院原因",
            trigger: "blue",
          },
        ],
        inpatientInstitution: [
          {
            required: true,
            message: "请输入住院机构",
            trigger: "blue",
          },
        ],
        recoveryCondition: [
          {
            required: true,
            message: "请选择健康恢复情况",
            trigger: "change",
          },
        ],
      },
    };
  },
  mounted() {
    console.log(this.hospitalizationDetail);
  },
  methods: {
    handleClose() {
      this.$emit("onclise", false);
      this.$refs["ruleForm"].resetFields();
      this.ruleForm = {};
    },
    handleSubmit() {
      if (this.ruleForm.id) {
        this.$refs["ruleForm"].validate((valid) => {
          if (valid) {
            this.ruleForm.oldManId = this.oldManId;
            updatehospitalization(this.ruleForm).then((res) => {
              if (res.code == 200) {
                this.handleClose();
              }
            });
          }
        });
      } else {
        this.$refs["ruleForm"].validate((valid) => {
          if (valid) {
            this.ruleForm.oldManId = this.oldManId;
            addhospitalization(this.ruleForm).then((res) => {
              if (res.code == 200) {
                this.handleClose();
              }
            });
          }
        });
      }
    },
  },
};
</script>
